package org.minhnhut.PhimSo;


import java.util.ArrayList;
import java.util.List;

import com.example.demolistview.R;


import android.content.Context;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;


public class MyAdapter extends ArrayAdapter<Film> {

	private Context context;
	private int idRes;
	ArrayList<Film> films ;
	public MyAdapter(Context context, int textViewResourceId, List<Film> objects) {
		super(context, textViewResourceId, objects);
		// TODO Auto-generated constructor stub
		this.context = context;
		this.idRes = textViewResourceId;
		this.films = (ArrayList<Film>) objects;
		
	}
	
	private class ViewHolder{
		
		ImageView imageView;
		TextView name;
		TextView year;
		TextView price;
		
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		
		ViewHolder viewHolder;
		if (convertView == null) {
			viewHolder = new ViewHolder();
			LayoutInflater inflater =  LayoutInflater.from(context);
			convertView = inflater.inflate(idRes, null);
			
			viewHolder.imageView = (ImageView) convertView.findViewById(R.id.img);
			viewHolder.name = (TextView) convertView.findViewById(R.id.txtTen);
			viewHolder.year = (TextView) convertView.findViewById(R.id.txtNam);
			viewHolder.price = (TextView) convertView.findViewById(R.id.txtGia);
			convertView.setTag(viewHolder);
		}
		else {
			viewHolder = (ViewHolder) convertView.getTag();
			}
		Film filmObject = films.get(position);
		viewHolder.imageView.setImageDrawable(filmObject.getImg());
		viewHolder.name.setText(filmObject.getFname());
		viewHolder.year.setText(filmObject.getFyear());
		viewHolder.price.setText(filmObject.getFprice());
		return convertView;
	
	}
	
}
	

	

